layui.define(['helper'], function (exports) {
	window.$ = layui.$;
	
	
	window.stepFormVerifyConf = {
	    	  //验证不能未空
	    	  required: function(value, item){ //value：表单的值、item：表单的DOM对象
	    	  			  if(value == ''){
							  var tabinx = $(item).data('tabinx');
							  $("#layertab"+tabinx).click();
	    	  				  if($(item).css("display") == 'none'){
	    	  					  window.scrollTo(0, $(item).parent().offset().top -10)
	    	  				  }else{
								  $(item).addClass('layui-form-danger');
								  $(item).focus();
	    	  					  window.scrollTo(0, $(item).offset().top - 10);
	    	  				  }
	    	  				  return item.getAttribute('data-label')+"不能为空";
	    	  			  }
	    	  			  return;
	    	  },
	    	  //验证是否手机号码
	    	  phone: function(value, item){ //value：表单的值、item：表单的DOM对象
	    	  			  var validationRule = '[/^1\d{10}$/';
	    	  			  if(new RegExp(validationRule).test(value) == false){
							  var tabinx = $(item).data('tabinx');
							  $("#layertab"+tabinx).click();
	    	  				  if($(item).css("display") == 'none'){
	    	  					  window.scrollTo(0, $(item).parent().offset().top -10)
	    	  				  }else{
								  $(item).addClass('layui-form-danger');
								  $(item).focus();
	    	  					  window.scrollTo(0, $(item).offset().top - 10);
	    	  				  }
	    	  				  return item.getAttribute('data-label')+"不是一个有效的手机号码";
	    	  			  }
	    	  			  return;
	    	  },
	    	  //验证是否邮箱
	    	  email: function(value, item){ //value：表单的值、item：表单的DOM对象
	    	  			  var validationRule = '[/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/';
	    	  			  if(new RegExp(validationRule).test(value) == false){
							  var tabinx = $(item).data('tabinx');
							  $("#layertab"+tabinx).click();
	    	  				  if($(item).css("display") == 'none'){
	    	  					  window.scrollTo(0, $(item).parent().offset().top -10)
	    	  				  }else{
								  $(item).addClass('layui-form-danger');
								  $(item).focus();
	    	  					  window.scrollTo(0, $(item).offset().top - 10);
	    	  				  }
	    	  				  return item.getAttribute('data-label')+"不是一个有效邮箱地址";
	    	  			  }
	    	  			  return;
	    	  },
	    	  //验证是否url
	    	  url: function(value, item){ //value：表单的值、item：表单的DOM对象
	    	  			  var validationRule = '[/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/';
	    	  			  if(new RegExp(validationRule).test(value) == false){
							  var tabinx = $(item).data('tabinx');
							  $("#layertab"+tabinx).click();
	    	  				  if($(item).css("display") == 'none'){
	    	  					  window.scrollTo(0, $(item).parent().offset().top -10)
	    	  				  }else{
								  $(item).addClass('layui-form-danger');
								  $(item).focus();
	    	  					  window.scrollTo(0, $(item).offset().top - 10);
	    	  				  }
	    	  				  return item.getAttribute('data-label')+"不是一个有效url";
	    	  			  }
	    	  			  return;
	    	  },
	    	  //验证是否数字
	    	  number: function(value, item){ //value：表单的值、item：表单的DOM对象
	    	  			  if(!value || isNaN(value)){
							  var tabinx = $(item).data('tabinx');
							  $("#layertab"+tabinx).click();
	    	  				  if($(item).css("display") == 'none'){
	    	  					  window.scrollTo(0, $(item).parent().offset().top -10)
	    	  				  }else{
								  $(item).addClass('layui-form-danger');
								  $(item).focus();
	    	  					  window.scrollTo(0, $(item).offset().top - 10);
	    	  				  }
	    	  				  return item.getAttribute('data-label')+"不是一个有效数字";
	    	  			  }
	    	  			  return;
	    	  },
	    	  //验证是否日期
	    	  date: function(value, item){ //value：表单的值、item：表单的DOM对象
	    	  			  var validationRule = '[/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/';
	    	  			  if(new RegExp(validationRule).test(value) == false){
							  var tabinx = $(item).data('tabinx');
							  $("#layertab"+tabinx).click();
	    	  				  if($(item).css("display") == 'none'){
	    	  					  window.scrollTo(0, $(item).parent().offset().top -10)
	    	  				  }else{
								  $(item).addClass('layui-form-danger');
								  $(item).focus();
	    	  					  window.scrollTo(0, $(item).offset().top - 10);
	    	  				  }
	    	  				  return item.getAttribute('data-label')+"不是一个有效日期";
	    	  			  }
	    	  			  return;
	    	  },
	    	  //验证是否身份证号码
	    	  identity: function(value, item){ //value：表单的值、item：表单的DOM对象
	    	  			  var validationRule = '[/(^\d{15}$)|(^\d{17}(x|X|\d)$)/';
	    	  			  if(new RegExp(validationRule).test(value) == false){
							  var tabinx = $(item).data('tabinx');
							  $("#layertab"+tabinx).click();
	    	  				  if($(item).css("display") == 'none'){
	    	  					  window.scrollTo(0, $(item).parent().offset().top -10)
	    	  				  }else{
								  $(item).addClass('layui-form-danger');
								  $(item).focus();
	    	  					  window.scrollTo(0, $(item).offset().top - 10);
	    	  				  }
	    	  				  return item.getAttribute('data-label')+"不是一个正确的身份证号";
	    	  			  }
	    	  			  return;
	    	  },
	};
	
	//分步骤表单按钮事件
	window.setepformButton = function(){
		//上一步按钮监听
		document.getElementById("upButton").onclick=function(){
			//获取当前
			var li = document.getElementById("layui-tab-ul").getElementsByTagName('li');
			for(i in li){
				if(li[i].className == 'layui-this'){
					var index= parseInt(li[i].getAttribute('data-index'));
					index--;
					document.getElementById("submitButton").style.display='none';
					if(index <= 0){
						//把上一步隐藏 把确认异常
						document.getElementById("upButton").style.display='none';
					}
					
					if(index > 0){
						document.getElementById("upButton").style.display='';
						document.getElementById("nextButton").style.display='';//把下一步隐藏
					}
					document.getElementById("layertab"+index).click();
					break;
				}
			}
		};
		//下一步按钮监听
		document.getElementById("nextButton").onclick=function(){
			//获取当前
			var li = document.getElementById("layui-tab-ul").getElementsByTagName('li');
			for(i in li){
				if(li[i].className == 'layui-this'){
					//下一步需要做的就是验证当前
					var index= parseInt(li[i].getAttribute('data-index'));
					//开始验证 把所有的表单拿到
					var formVerify = setepformVerify('stepFormItem'+index);
					if(formVerify){
						return layer.msg(formVerify, {
							icon: 5,
							shift: 6
						});
					}
					index ++;
					if(index > 0){
						document.getElementById("upButton").style.display='';//把上一步显示出来
					}
					if(index >= li.length - 1){
						document.getElementById("submitButton").style.display='';//把确认显示出来
						document.getElementById("nextButton").style.display='none';//把下一步隐藏
					}
					document.getElementById("layertab"+index).click();
					break;
				}
			}
		};
	}
	
	window.setepformVerify = function(id){
		//傻 这样子还怎么取数据
		var inputs = $("#"+id).find("input,select,textarea");
		var errmsg = false;
		inputs.each(function(index){
			var layVerify = this.getAttribute('lay-verify');
			if(layVerify){
				var VerifyArr = layVerify.split("|");
				for(ii in VerifyArr){
					var field = VerifyArr[ii];
					var evalstr = 'var errormsg = stepFormVerifyConf.'+field+'($(this).val(), this);';
					eval(evalstr);
					if(errormsg != undefined){
						errmsg = errormsg;
						return false;
					}
				}
			}
		});
		return errmsg;
	}
	
	
	window.formVerifyConf = {
		  //验证不能未空
		  required: function(value, item){ //value：表单的值、item：表单的DOM对象
			  if(value == ''){
				  if($(item).css("display") == 'none'){
					  window.scrollTo(0, $(item).parent().offset().top -10)
				  }else{
					  window.scrollTo(0, $(item).offset().top - 10);
				  }
				  return item.getAttribute('data-label')+"不能为空";
			  }
			  return;
		  },
		  //验证是否手机号码
		  phone: function(value, item){ //value：表单的值、item：表单的DOM对象
			  var validationRule = '[/^1\d{10}$/';
			  if(new RegExp(validationRule).test(value) == false){
				  if($(item).css("display") == 'none'){
					  window.scrollTo(0, $(item).parent().offset().top -10)
				  }else{
					  window.scrollTo(0, $(item).offset().top - 10);
				  }
				  return item.getAttribute('data-label')+"不是一个有效的手机号码";
			  }
			  return;
		  },
		  //验证是否邮箱
		  email: function(value, item){ //value：表单的值、item：表单的DOM对象
			  var validationRule = '[/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/';
			  if(new RegExp(validationRule).test(value) == false){
				  if($(item).css("display") == 'none'){
					  window.scrollTo(0, $(item).parent().offset().top -10)
				  }else{
					  window.scrollTo(0, $(item).offset().top - 10);
				  }
				  return item.getAttribute('data-label')+"不是一个有效邮箱地址";
			  }
			  return;
		  },
		  //验证是否url
		  url: function(value, item){ //value：表单的值、item：表单的DOM对象
			  var validationRule = '[/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/';
			  if(new RegExp(validationRule).test(value) == false){
				  if($(item).css("display") == 'none'){
					  window.scrollTo(0, $(item).parent().offset().top -10)
				  }else{
					  window.scrollTo(0, $(item).offset().top - 10);
				  }
				  return item.getAttribute('data-label')+"不是一个有效url";
			  }
			  return;
		  },
		  //验证是否数字
		  number: function(value, item){ //value：表单的值、item：表单的DOM对象
			  if(!value || isNaN(value)){
				  if($(item).css("display") == 'none'){
					  window.scrollTo(0, $(item).parent().offset().top -10)
				  }else{
					  window.scrollTo(0, $(item).offset().top - 10);
				  }
				  return item.getAttribute('data-label')+"不是一个有效数字";
			  }
			  return;
		  },
		  //验证是否日期
		  date: function(value, item){ //value：表单的值、item：表单的DOM对象
			  var validationRule = '[/^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/';
			  if(new RegExp(validationRule).test(value) == false){
				  if($(item).css("display") == 'none'){
					  window.scrollTo(0, $(item).parent().offset().top -10)
				  }else{
					  window.scrollTo(0, $(item).offset().top - 10);
				  }
				  return item.getAttribute('data-label')+"不是一个有效日期";
			  }
			  return;
		  },
		  //验证是否身份证号码
		  identity: function(value, item){ //value：表单的值、item：表单的DOM对象
			  var validationRule = '[/(^\d{15}$)|(^\d{17}(x|X|\d)$)/';
			  if(new RegExp(validationRule).test(value) == false){
				  if($(item).css("display") == 'none'){
					  window.scrollTo(0, $(item).parent().offset().top -10)
				  }else{
					  window.scrollTo(0, $(item).offset().top - 10);
				  }
				  return item.getAttribute('data-label')+"不是一个正确的身份证号";
			  }
			  return;
		  },
	};
	
	window.cloneOneImage = function(obj, key){
		//关闭 清空隐藏域
		let previewText = '未知类型';
		switch ($(obj).parent().data('type')){
			case 'one-image':
				previewText = '请选择一张图片';
			break;
			case 'one-video':
				previewText = '请选择一个视频';
			break;
			case 'one-audio':
				previewText = '请选择一个音频';
			break;
			case 'one-document':
				previewText = '请选择一个文件';
			break;
			default:
			break;
		}
		$(obj).parent().find('.image_input').val('');
		$(obj).parent().find('.image-preview').html(previewText);
		$(obj).parent().find('.clone-one-image').css('display', 'none');
		$(obj).parent().find('.preview-text').html('');
		document.getElementById("validation-"+key).value = "";
	}
	
	window.oneImageSelect = function(obj, key){
		if(obj != undefined){
			window.tempObj = obj;
			window.tempKey = key;
			var selected = '';
			var inputHidden = $(obj).parent().find('.image_input').val();
			if(inputHidden){
				var evalVal = eval('('+inputHidden+')');
				selected = evalVal.image_id;
			}
			layer.open({
				  type: 2,
				  title: "图片选择",
				  shadeClose: true,
				  shade: 0.7,
				  offset:'r',
				  area: ['95%', '95%'],
				  scrollbar: false,
				  content: appRoute.finderImage+'&multiple=0&fun=oneImageSelect&selected='+selected
			});
		}else if(typeof tempJson != "undefined"){
			if(strrpos(tempJson.url, window.location.host) >= 0){
				tempJson.url = explode(window.location.host, tempJson.url)[1];
			}
			var obj = window.tempObj;
			var key = window.tempKey;
			//删除网址
			$(obj).html('<img alt="" src="'+tempJson.url+'" height="200px">');
			//把关闭按钮打开
			$(obj).parent().find('.clone-one-image').css('display', '');//把关闭按钮显示出来
			let inputData = {
				"image_id": tempJson.image_id,
				"original": tempJson.original,
				"url": tempJson.url
			};
			$(obj).parent().find('.image_input').val(json_encode(inputData));//设置隐藏域
			
			$(obj).parent().find('.preview-text').html('<input readonly="readonly" title="'+tempJson.original+'" class="preview-text-input" type="text" value="'+tempJson.original+'" />');
			//关闭窗口
			document.getElementById("validation-"+key).value = 1;
			layer.closeAll();
		}
	}
	
	window.oneVideoSelect = function(obj, key){
		if(obj != undefined){
			window.tempObj = obj;
			window.tempKey = key;
			var selected = '';
			var inputHidden = $(obj).parent().find('.image_input').val();
			if(inputHidden){
				var evalVal = eval('('+inputHidden+')');
				selected = evalVal.video_id;
			}
			layer.open({
				  type: 2,
				  title: "视频选择",
				  shadeClose: true,
				  scrollbar: false,
				  shade: 0.7,
				  offset:'r',
				  area: ['95%', '95%'],
				  content: appRoute.finderVideo+'&multiple=0&fun=oneVideoSelect&selected='+selected
			});
		}else if(typeof tempJson != "undefined"){
			let thumbnail = tempJson.thumbnail;
			var reg=/<img [^>]*src=['"]([^'"]+)[^>]*>/gi;
			thumbnail = thumbnail.replace(reg,"$1");
			//拿到这个
			
			let src = tempJson.url;
			if(strrpos(tempJson.thumbnail, window.location.host) >= 0){
				thumbnail = explode(window.location.host, thumbnail)[1];
				src = explode(window.location.host, src)[1];
			}
			
			let original = tempJson.original;
			var obj = window.tempObj;
			var key = window.tempKey;
			//删除网址
			$(obj).html('<img alt="" src="'+thumbnail+'" height="200px">');
			//把关闭按钮打开
			$(obj).parent().find('.clone-one-image').css('display', '');//把关闭按钮显示出来
			
			let inputData = {
				"video_id": tempJson.video_id,
				"thumbnail": thumbnail,
				"original": original,
				"url": src
			};
			
			$(obj).parent().find('.image_input').val(json_encode(inputData));//设置隐藏域
			
			$(obj).parent().find('.preview-text').html('<input readonly="readonly" title="'+original+'" class="preview-text-input" type="text" value="'+original+'" />');
			//关闭窗口
			document.getElementById("validation-"+key).value = 1;
			layer.closeAll();
		}
	}
	
	window.moreVideoSelect = function(obj, key){
		if(obj != undefined){
			window.tempObj = obj;
			window.tempKey = key;
			
			//现在已经选择了多少个
			var inputNum = 0 ;
			var selected = [];
			$(window.tempObj).parent().parent().parent().find('.image_input').each(function(index){
				if(this.value != ''){
					var evalVal = eval('('+this.value+')');
					array_push(selected, evalVal.video_id);
					inputNum ++;
				}
			});
			window.tempSelected = selected;
			selected = implode(',' , selected);
			if(inputNum >= appConfig.finderSelectVideoMaxNum){
				noticeMsg('error', '最多可设'+appConfig.finderSelectVideoMaxNum+'个视频,如需继续设定请先删除部分视频再继续');
				return false;
			}
			layer.open({
				  type: 2,
				  title: "视频选择",
				  shadeClose: true,
				  scrollbar: false,
				  shade: 0.7,
				  offset:'r',
				  area: ['90%', '90%'],
				  content: appRoute.finderVideo+'&multiple=1&fun=moreVideoSelect&existnum='+inputNum+"&selected="+selected
			});
		}else if(typeof tempJson != "undefined"){
			var key = window.tempKey;
			var obj = window.tempObj;
			//image_input
			var tpl = '<div class="finder-image">\
				<div class="finder-image-preview" data-type="'+$(obj).parent().data('type')+'">\
					 <div class="clone-one-image" style="position: absolute; right: 5px; top:5px; z-index: 99;" onclick="cloneMoreImage(this, \''+key+'\');">\
						  <i class="layui-icon layui-icon-close-fill" style="font-size: 24px;"></i>\
					  </div>\
					<input class="image_input"  name="'+key+'[]" value=\'{{src}}\' type="hidden"  />\
					<div class="image-preview" onclick="moreVideoSelect(this, \''+key+'\');">{{preview}}</div>\
					<div class="preview-text" >{{previewtext}}</div>\
				</div>\
			</div>';
			let html = '';
			var  currentSelectNum = 0; 
			for(i in tempJson){
				if(in_array(tempJson[i]['video_id'], window.tempSelected)){
					continue;
				}
				currentSelectNum ++;
				var src = tempJson[i]['url'];
				var title = tempJson[i]['original'];
				var thumbnail = tempJson[i]['thumbnail'];
				var reg=/<img [^>]*src=['"]([^'"]+)[^>]*>/gi;
				thumbnail = thumbnail.replace(reg,"$1");
				
				var inputData = {
					"video_id": tempJson[i]['video_id'],
					"original": title,
					"thumbnail": thumbnail,
					"url": src
				};
				html += str_replace(['{{preview}}', '{{previewtext}}', '{{src}}'], ['<img alt="" src="'+thumbnail+'" height="200px">', '<input readonly="readonly" title="'+title+'" class="preview-text-input" type="text" value="'+title+'" />', json_encode(inputData)], tpl);
			}
			
			if(currentSelectNum + window.tempSelected.length > appConfig.finderSelectVideoMaxNum){
				noticeMsg('error', '最多只能设'+appConfig.finderSelectVideoMaxNum+'个视频');
				return false;
			}
			//alert(newHtml);return;
			//如果是一个并且上级的image_input 为false的情况下
			var tag = $(obj).parent().parent().parent().find('.finder-image');
			let val0 = tag.eq(0).find('.image_input').eq(0).val();
			if(tag.length == 1 && val0 == ''){
				$(obj).parent().parent().parent().html(html);
			}else{
				$(obj).parent().parent().parent().append(html);//这里应该是追加
			}
			document.getElementById("validation-"+key).value = 1;
			//关闭窗口
			layer.closeAll();
		}
	}
	
	window.moreImageSelect = function(obj, key){
		
		if(obj != undefined){
			window.tempObj = obj;
			window.tempKey = key;
			
			//现在已经选择了多少个
			var inputNum = 0 ;
			var selected = [];
			$(window.tempObj).parent().parent().parent().find('.image_input').each(function(index){
				if(this.value != ''){
					inputNum ++;
					var evalVal = eval('('+this.value+')');
					array_push(selected, evalVal.image_id);
				}
			});
			window.tempSelected = selected;
			selected = implode(',' , selected);
			if(inputNum >= appConfig.finderSelectImageMaxNum){
				noticeMsg('error', '最多可设'+appConfig.finderSelectImageMaxNum+'张图片,如需继续设定请先删除部分图片再继续');
				return false;
			}
			layer.open({
				  type: 2,
				  title: "图片选择",
				  shadeClose: true,
				  scrollbar: false,
				  shade: 0.7,
				  offset:'r',
				  area: ['90%', '90%'],
				  content: appRoute.finderImage+'&multiple=1&fun=moreImageSelect&existnum='+inputNum+'&selected='+selected
			});
		}else if(typeof tempJson != "undefined"){
			var key = window.tempKey;
			var obj = window.tempObj;
			//image_input
			var tpl = '<div class="finder-image">\
				<div class="finder-image-preview" data-type="'+$(obj).parent().data('type')+'">\
					 <div class="clone-one-image" style="position: absolute; right: 5px; top:5px; z-index: 99;" onclick="cloneMoreImage(this, \''+key+'\');">\
						  <i class="layui-icon layui-icon-close-fill" style="font-size: 24px;"></i>\
					  </div>\
					<input class="image_input"  name="'+key+'[]" value=\'{{src}}\' type="hidden"  />\
					<div class="image-preview" onclick="moreImageSelect(this, \''+key+'\');">{{preview}}</div>\
					<div class="preview-text" >{{previewtext}}</div>\
				</div>\
			</div>';
			let html = '';
			var  currentSelectNum = 0; 
			for(i in tempJson){
				if(in_array(tempJson[i]['image_id'], window.tempSelected)){
					continue;
				}
				currentSelectNum ++;
				var imageId = tempJson[i]['image_id'];
				var src = tempJson[i]['url'];
				var title = tempJson[i]['original'];
				var inputData = {
					"image_id": imageId,
					"original": title,
					"url": src
				};
				html += str_replace(['{{preview}}', '{{previewtext}}', '{{src}}'], ['<img alt="" src="'+src+'" height="200px">', '<input readonly="readonly" title="'+title+'" class="preview-text-input" type="text" value="'+title+'" />', json_encode(inputData)], tpl);
			}
			if(currentSelectNum + window.tempSelected.length > appConfig.finderSelectImageMaxNum){
				noticeMsg('error', '最多只能设'+appConfig.finderSelectImageMaxNum+'张图片');
				return false;
			}
			
			//如果是一个并且上级的image_input 为false的情况下
			var tag = $(obj).parent().parent().parent().find('.finder-image');
			let val0 = tag.eq(0).find('.image_input').eq(0).val();
			if(tag.length == 1 && val0 == ''){
				$(obj).parent().parent().parent().html(html);
			}else{
				$(obj).parent().parent().parent().append(html);//这里应该是追加
			}
			document.getElementById("validation-"+key).value = 1;
			//关闭窗口
			layer.closeAll();
		}
		
		
	}
	
	window.cloneMoreImage = function(obj, key){
		var tag = $(obj).parent().parent().parent().find('.finder-image');
		if(tag.length > 1){
			$(obj).parent().parent().remove();//干掉自己
		}else if(tag.length == 1){
			document.getElementById("validation-"+key).value = "";
			//清除数据
			let previewText = '未知类型';
			switch ($(obj).parent().data('type')){
				case 'more-image':
					previewText = '请选择一张或多张图片';
				break;
				case 'more-video':
					previewText = '请选择一个视频或多个视频';
				break;
				case 'more-audio':
					previewText = '请选择一个音频或多个音频';
				break;
				default:
				break;
			}
			$(obj).parent().find('.image_input').val('');
			$(obj).parent().find('.image-preview').html(previewText);
			$(obj).parent().find('.clone-one-image').css('display', 'none');
			$(obj).parent().find('.preview-text').html('');
		}
	}
	
	window.oneAudioSelect = function(obj, key){
		if(obj != undefined){
			window.tempObj = obj;
			window.tempKey = key;
			window.finderSelectMaxNum = appConfig.finderSelectAudioMaxNum;
			var content = appRoute.finderAudio;
			var inputHidden = $(obj).parent().find('.layui-tab-title').find('.image_input').val();
			var selected = '';
			if(inputHidden){
				var evalVal = eval('('+inputHidden+')');
				selected = evalVal.audio_id;
			}
			layer.open({
				  type: 2,
				  title: "音频选择",
				  shadeClose: true,
				  scrollbar: false,
				  shade: 0.7,
				  offset:'r',
				  area: ['90%', '90%'],
				  content: content+'&fun=oneAudioSelect&selected='+selected
			});
		}else{
			layer.closeAll();
			var url = tempJson.url;
			if(strrpos(tempJson.url, window.location.host) >= 0){
				url = explode(window.location.host, tempJson.src)[1];
			}
			var inputData = {
				"audio_id": tempJson.audio_id,
				"original": tempJson.original,
				"url": tempJson.url
			};
			
			var obj = window.tempObj;
			var key = window.tempKey;
			var html = '<li style="border-radius: 2px;height:26px; margin-left: 5px; margin-top:5px;line-height:1.8em;padding: 0 8px;background: #fff;color: #000;" >'+tempJson.original+"<input class='image_input' type='hidden' name='"+key+"' value='"+json_encode(inputData)+"' />"+'<i class="layui-icon layui-unselect layui-tab-close" onclick="javascript:this.parentNode.parentNode.removeChild(this.parentNode);document.getElementById(\'validation-'+key+'\').value=\'\';">ဆ</i></li>';
			$(obj).parent().find('.layui-tab-title').html(html);
			document.getElementById("validation-"+key).value = 1;
		}
		
	}
	
	window.moreAudioSelect = function(obj, key){
			
			if(obj != undefined){
				window.tempObj = obj;
				window.tempKey = key;
				window.finderSelectMaxNum = appConfig.finderSelectAudioMaxNum;
				var content = appRoute.finderAudio;
				if($(obj).parent().find('.layui-tab-title').find('.image_input').length >= finderSelectMaxNum){
					return noticeMsg('error', '最多可设'+finderSelectMaxNum+'个音频,如需继续设定请先删除部分再继续');
				}
				var selected = [];
				$(obj).parent().find('.layui-tab-title').find('.image_input').each(function(index){
					var evalVal = eval('('+this.value+')');
					array_push(selected, evalVal.audio_id);
				});
				window.tempSelected = selected;
				selected = implode(',' , selected);
				layer.open({
					  type: 2,
					  title: "音频选择",
					  shadeClose: true,
					  scrollbar: false,
					  shade: 0.7,
					  offset:'r',
					  area: ['90%', '90%'],
					  content: content+'&fun=moreAudioSelect&selected='+selected
				});
			}else{
				
				var obj = window.tempObj;
				var key = window.tempKey;
				let table = $(obj).parent().find('.layui-tab-title').find('table');
				if(table.length == 0){
					var tr = '';
					var  currentSelectNum = 0; 
					for(i in tempJson){
						currentSelectNum++;
						var inputData = {
							"audio_id": tempJson[i].audio_id,
							"original": tempJson[i].original,
							"url": tempJson[i].url
						};
						tr += '<tr>\
							  <td>'+tempJson[i]['original']+'<input class="image_input" type="hidden" name="'+key+'[]" value=\''+json_encode(inputData)+'\' /></td>\
							  <td><a onclick="cloneMoreDocument(this, \''+key+'\')" href="javascript:void(0)">删除</a></td>\
						  </tr>';
					}
					if(currentSelectNum > appConfig.finderSelectAudioMaxNum){
						return noticeMsg('error', '最多只能设'+appConfig.finderSelectAudioMaxNum+'个音频');
					}
					let html = '<table class="layui-table">\
					  <thead>\
						<tr>\
							<th width="60%">文件</th>\
							<th>操作</th>\
						</tr>\
					  </thead>\
					  <tbody>'+tr+'</tbody>\
					</table>';
					$(obj).parent().find('.layui-tab-title').html(html);
					document.getElementById("validation-"+key).value = 1;
				}else{
					var tr = '';
					var  currentSelectNum = 0; 
					for(i in tempJson){
						if(in_array(tempJson[i].audio_id, window.tempSelected)){
							continue;
						}
						currentSelectNum ++;
						var inputData = {
							"audio_id": tempJson[i].audio_id,
							"original": tempJson[i].original,
							"url": tempJson[i].url
						};
						tr += '<tr>\
							  <td>'+tempJson[i]['original']+'<input class="image_input" type="hidden" name="'+key+'[]" value=\''+json_encode(inputData)+'\' /></td>\
							  <td><a onclick="cloneMoreDocument(this, \''+key+'\')" href="javascript:void(0)">删除</a></td>\
						  </tr>';
					}
					if(currentSelectNum + window.tempSelected.length > appConfig.finderSelectAudioMaxNum){
						noticeMsg('error', '最多只能设'+appConfig.finderSelectAudioMaxNum+'个音频');
						return false;
					}
					table.eq(0).append(tr);  
					document.getElementById("validation-"+key).value = 1;
				}
				layer.closeAll();
			}
			
		}
	
	window.oneDocumentSelect = function(obj, key){
		if(obj != undefined){
			window.tempObj = obj;
			window.tempKey = key;
			var content = appRoute.finderFile;
			var inputHidden = $(obj).parent().find('.layui-tab-title').find('.image_input').val();
			var selected = '';
			if(inputHidden){
				var evalVal = eval('('+inputHidden+')');
				selected = evalVal.file_id;
			}
			layer.open({
				  type: 2,
				  title: "文件选择",
				  shadeClose: true,
				  scrollbar: false,
				  shade: 0.7,
				  offset:'r',
				  area: ['90%', '90%'],
				  content: content+'&fun=oneDocumentSelect&selected='+selected
			});
		}else{
			layer.closeAll();
			var url = tempJson.url;
			if(strrpos(tempJson.url, window.location.host) >= 0){
				url = explode(window.location.host, tempJson.src)[1];
			}
			var inputData = {
				"file_id": tempJson.file_id,
				"original": tempJson.original,
				"url": tempJson.url
			};
			
			var obj = window.tempObj;
			var key = window.tempKey;
			var html = '<li style="border-radius: 2px;height:26px; margin-left: 5px; margin-top:5px;line-height:1.8em;padding: 0 8px;background: #fff;color: #000;" >'+tempJson.original+"<input class='image_input' type='hidden' name='"+key+"' value='"+json_encode(inputData)+"' />"+'<i class="layui-icon layui-unselect layui-tab-close" onclick="javascript:this.parentNode.parentNode.removeChild(this.parentNode);document.getElementById(\'validation-'+key+'\').value=\'\';">ဆ</i></li>';
			$(obj).parent().find('.layui-tab-title').html(html);
			document.getElementById("validation-"+key).value = 1;
		}
		
	}
	
	window.cloneOneDocument = function(obj){
		alert("关闭");
	}
	
	window.moreDocumentSelect = function(obj, key){
		
		if(obj != undefined){
			window.tempObj = obj;
			window.tempKey = key;
			var content = appRoute.finderFile;
			window.finderSelectMaxNum = appConfig.finderSelectDocumentMaxNum;
			
			
			if($(obj).parent().find('.layui-tab-title').find('.image_input').length >= finderSelectMaxNum){
				return noticeMsg('error', '最多可设'+finderSelectMaxNum+'个文件,如需继续设定请先删除部分再继续');
			}
			var selected = [];
			$(obj).parent().find('.layui-tab-title').find('.image_input').each(function(index){
				var evalVal = eval('('+this.value+')');
				array_push(selected, evalVal.file_id);
			});
			window.tempSelected = selected;
			selected = implode(',' , selected);
			layer.open({
				  type: 2,
				  title: "文件选择",
				  shadeClose: true,
				  scrollbar: false,
				  shade: 0.7,
				  offset:'r',
				  area: ['90%', '90%'],
				  content: content+'&fun=moreDocumentSelect&selected='+selected
			});
		}else{
			
			var obj = window.tempObj;
			var key = window.tempKey;
			let table = $(obj).parent().find('.layui-tab-title').find('table');
			if(table.length == 0){
				var tr = '';
				var  currentSelectNum = 0; 
				for(i in tempJson){
					if(in_array(tempJson[i].file_id, window.tempSelected)){
						continue;
					}
					currentSelectNum++;
					var inputData = {
						"file_id": tempJson[i].file_id,
						"original": tempJson[i].original,
						"url": tempJson[i].url
					};
					tr += '<tr>\
						  <td>'+tempJson[i]['original']+'<input class="image_input" type="hidden" name="'+key+'[]" value=\''+json_encode(inputData)+'\' /></td>\
						  <td><a onclick="cloneMoreDocument(this, \''+key+'\')" href="javascript:void(0)">删除</a></td>\
					  </tr>';
				}
				if(currentSelectNum  + window.tempSelected.length > appConfig.finderSelectDocumentMaxNum){
					return noticeMsg('error', '最多只能设'+appConfig.finderSelectDocumentMaxNum+'个文件');
				}
				let html = '<table class="layui-table">\
				  <thead>\
					<tr>\
						<th width="60%">文件</th>\
						<th>操作</th>\
					</tr>\
				  </thead>\
				  <tbody>'+tr+'</tbody>\
				</table>';
				$(obj).parent().find('.layui-tab-title').html(html);
				document.getElementById("validation-"+key).value = 1;
			}else{
				var tr = '';
				var  currentSelectNum = 0; 
				for(i in tempJson){
					if(in_array(tempJson[i].file_id, window.tempSelected)){
						continue;
					}
					currentSelectNum++;
					var inputData = {
						"file_id": tempJson[i].file_id,
						"original": tempJson[i].original,
						"url": tempJson[i].url
					};
					tr += '<tr>\
						  <td>'+tempJson[i]['original']+'<input class="image_input" type="hidden" name="'+key+'[]" value=\''+json_encode(inputData)+'\' /></td>\
						  <td><a onclick="cloneMoreDocument(this, \''+key+'\')" href="javascript:void(0)">删除</a></td>\
					  </tr>';
				}
				
				if(currentSelectNum + window.tempSelected.length > appConfig.finderSelectDocumentMaxNum){
					return noticeMsg('error', '最多只能设'+appConfig.finderSelectDocumentMaxNum+'个文件');
				}
				document.getElementById("validation-"+key).value = 1;
				table.eq(0).append(tr);  
			}
			layer.closeAll();
		}
		
	}
	
	window.cloneMoreDocument = function(obj, key){
		if($(obj).parent().parent().parent().find('tr').length == 1){
			//全删了
			document.getElementById("validation-"+key).value = "";
			$(obj).parent().parent().parent().parent().remove();
		}else{
			$(obj).parent().parent().remove();
		}
		
	}
	
	window.oneOpenSelect = function(obj, key){
		if(obj != undefined){
			window.tempObj = obj;
			window.tempKey = key;
			
			if($(obj).data('valuetable') == false) return noticeMsg('error', "value_table未设置");
			var inputHidden = $(obj).parent().find('.layui-tab-title').find('.input-hidden');
			var invals = [];
			inputHidden.each(function(index){
				var evalVal = eval('('+$(this).val()+')');
				array_push(invals, evalVal.id);
			});
			var invalsStr = '';
			if(invals) invalsStr = implode(',',  invals);
			layer.open({
				  type: 2,
				  title: $(obj).data('title'),
				  shadeClose: true,
				  scrollbar: false,
				  shade: 0.2,
				  offset: 'auto',
				  area: ['90%', '90%'],
				  content: '../finder.html?api=/admin/dbfinder/'+$(obj).data('valuetable')+'&fun=oneOpenSelect&selected='+invalsStr
			});
			
		}else{
			layer.closeAll();
			var fieldId = '';
			var fieldTitle = '';
			var fieldNum = 0;
			for(i in tempField){
				if(fieldNum == 0){
					fieldId = i;
				}
				
				if(fieldNum == 1){
					fieldTitle = i;
				}
				fieldNum++;
			}
			eval('fieldId = tempJson.'+fieldId);
			eval('fieldTitle = tempJson.'+fieldTitle);
			
			var inputData = {
				'id': fieldId,
				'title': fieldTitle
			};
			
			var obj = window.tempObj;
			var key = window.tempKey;
			var html = '<li style="border-radius: 2px;height:26px; margin-left: 5px; margin-top:5px;line-height:1.8em;padding: 0 8px;background: #fff;color: #000;" >'+fieldTitle+"<input class='input-hidden' type='hidden' name='"+key+"' value='"+json_encode(inputData)+"' />"+'<i class="layui-icon layui-unselect layui-tab-close" onclick="javascript:this.parentNode.parentNode.removeChild(this.parentNode);document.getElementById(\'validation-'+key+'\').value=\'\';">ဆ</i></li>';
			$(obj).parent().find('.layui-tab-title').html(html);
			document.getElementById("validation-"+key).value = 1;
		}
		
	}
	
	window.moreOpenSelect = function(obj, key){
		var maxLi = appConfig.finderSelectCheckboxMaxNum;
		if(obj != undefined){
			if($(obj).parent().find('ul').eq(0).find('li').length >= maxLi){
				return noticeMsg('error', "最大只能设置"+maxLi+"个,如需继续设定请先删除部分再继续");
			}
			//if()
			window.tempObj = obj;
			window.tempKey = key;
			
			if($(obj).data('valuetable') == false) return noticeMsg('error', "value_table未设置");
			var inputHidden = $(obj).parent().find('.layui-tab-title').find('.input-hidden');
			var invals = [];
			inputHidden.each(function(index){
				var evalVal = eval('('+$(this).val()+')');
				array_push(invals, evalVal.id);
			});
			window.tempSelected = invals;
			var invalsStr = '';
			if(invals) invalsStr = implode(',', invals);
			//做一个最大限制
			layer.open({
				  type: 2,
				  title: $(obj).data('title'),
				  shadeClose: true,
				  scrollbar: false,
				  shade: 0.2,
				  offset: 'auto',
				  area: ['90%', '90%'],
				  content: '../finder.html?api=/admin/dbfinder/'+$(obj).data('valuetable')+'&fun=moreOpenSelect&selected='+invalsStr
			});
			
		}else{
			var fieldId = '';
			var fieldTitle = '';
			var fieldNum = 0;
			for(i in tempField){
				if(fieldNum == 0){
					fieldId = i;
				}
				
				if(fieldNum == 1){
					fieldTitle = i;
				}
				fieldNum++;
			}
			var obj = window.tempObj;
			var key = window.tempKey;
			
			var inputHidden = $(obj).parent().find('.layui-tab-title').find('.input-hidden');
			var invals = [];
			inputHidden.each(function(index){
				array_push(invals, $(this).val());
			});
			
			var html = '';
			var  currentSelectNum = 0; 
			for(i in tempJson){
				eval('fieldIdVal = tempJson[i].'+fieldId);
				eval('fieldTitleVal = tempJson[i].'+fieldTitle);
				
				var inputData = {
					'id': fieldIdVal,
					'title': fieldTitleVal
				};
				inputData = json_encode(inputData);
				
				if(!in_array(inputData, invals)){
					currentSelectNum++;
					var substrdd = substr(fieldTitleVal, 0, 24);
					if(substrdd != fieldTitleVal){
						substrdd += '...';
					}
					var fieldTitleVal = substrdd;
					html += '<li style="border-radius: 2px;height:26px; margin-left: 5px; margin-top:5px;line-height:1.8em;padding: 0 8px;background: #fff;color: #000;" >'+fieldTitleVal+"<input class='input-hidden' type='hidden' name='"+key+"[]' value='"+inputData+"' />"+'<i class="layui-icon layui-unselect layui-tab-close" onclick="javascript:if(this.parentNode.parentNode.getElementsByTagName(\'li\').length <= 1){document.getElementById(\'validation-'+key+'\').value=\'\';};this.parentNode.parentNode.removeChild(this.parentNode);">ဆ</i></li>';
				}
			}
			if(currentSelectNum + window.tempSelected.length > maxLi){
				return noticeMsg('error', "最大只能设置"+maxLi+"个");
			}
			layer.closeAll();
			$(obj).parent().find('.layui-tab-title').append(html);
			document.getElementById("validation-"+key).value = 1;
		}
	}
	
	window.stepLayFormData = function(data, json){
		var fileData = data.field;
		var stepform = json.stepform_fields;//这算是备用字段了
		for(i in stepform){
			var field = stepform[i]['field']; 
			for(ii in field){
				var item = field[ii];
				switch (item['input_type']){
					case 'date':
						if(item['type'] == 'int'){
							var key = stepform[i]['db_table']+"["+ii+"]";
							eval("fileData['"+key+"'] = strtotime(fileData['"+key+"']);");
						}
						break;
					case 'time':
						if(item['type'] == 'int'){
							var key = stepform[i]['db_table']+"["+ii+"]";
							eval("fileData['"+key+"'] = strtotime(fileData['"+key+"']);");
						}
						break;	
					default:
						break;
				}
			}
		}
		
		var formdata = new FormData();
		
		var inputFile = document.getElementsByClassName('inputFile');
		for(i in inputFile){
		  var mythis = inputFile[i];
		  if(inputFile[i]['files']){
			  formdata.append(mythis['name'],mythis.files[0]);
		  }
		}
			
		for(i in fileData){
		  formdata.append(i,fileData[i]);
		}
		if($_GET['_method_']){
			formdata.append('_method_',$_GET['_method_']);
		}
		return formdata;
		
	};
	
	window.layFormData = function(data, json){
		var fileData = data.field;
		var field = json.table_struct.field;
		//已经处理掉有value值的了
		for(i in field){
		  switch (field[i]['input_type']) {
			case 'date':
				//将日期转时间戳
				if(field[i]['type'] == 'int'){
					document.getElementById('_method').click();
					document.getElementById(i).value;
					fileData[i] = strtotime(document.getElementById(i).value);//转时间戳
				}
				break;
			case 'time':
				//将日期转时间戳
				if(field[i]['type'] == 'int'){
					document.getElementById('_method').click();
					document.getElementById(i).value;
					fileData[i] = strtotime(document.getElementById(i).value);//转时间戳
				}
				break;
			default:
				break;
			}
		}
			
		var formdata=new FormData();
		
		var inputFile = document.getElementsByClassName('inputFile');
		for(i in inputFile){
		  var mythis = inputFile[i];
		  if(inputFile[i]['files']){
			  formdata.append(mythis['name'],mythis.files[0]);
		  }
		}
			
		for(i in fileData){
		  formdata.append(i,fileData[i]);
		}
		if($_GET['_method_']){
			formdata.append('_method_',$_GET['_method_']);
		}
		return formdata;
	};
	//禁止滚动条滚动
	window.unScroll = function(){
		var top = $(document).scrollTop();
		$(document).on('scroll.unable',function (e) {
			$(document).scrollTop(top);
		})
	}
	//移除禁止滚动条滚动
	window.removeUnScroll = function() {
	    $(document).unbind("scroll.unable");
	}
	exports('formbuilder', window);//导出
});	